import { defHttp } from '@/utils/http/axios';
import {
  AccountListGetResultModel,
  AccountListItem,
  AccountParams,
} from '@/api/system/model/accountModel';
import { UnwrapRef } from 'vue';

const basePath = '/system/sysUser/';
const buildUrl = (url: string) => basePath + url;
enum Api {
  AccountPageQuery = 'pageQuery',
  AccountAddOrEdit = 'addOrUpdate',
  IsAccountExist = '/system/system/userInfoByName',
  QueryById = 'queryById',
  DeleteById = 'deleteById',
}

export const accountPageQuery = (params: AccountParams) =>
  defHttp.post<AccountListGetResultModel>(
    {
      url: buildUrl(Api.AccountPageQuery),
      params: { page: params.page, pageSize: params.pageSize, t: params },
    },
    { errorMessageMode: 'none' },
  );

export const accountAddOrEdit = (params) =>
  defHttp.post({ url: buildUrl(Api.AccountAddOrEdit), params }, { errorMessageMode: 'none' });

export const queryById = (userId: UnwrapRef<string>) =>
  defHttp.get<AccountListItem>(
    { url: buildUrl(Api.QueryById + '/' + userId) },
    { errorMessageMode: 'none' },
  );

export const deleteById = (userId) =>
  defHttp.get<AccountListItem>(
    { url: buildUrl(Api.DeleteById + '/' + userId) },
    { errorMessageMode: 'none' },
  );

export const isAccountExist = (account: string) =>
  defHttp.get({ url: Api.IsAccountExist + '/' + account }, { errorMessageMode: 'none' });
